package com.dianzi.certification.controller;

import com.dianzi.certification.dto.UserLoginDTO;
import com.dianzi.certification.dto.UserRegisterDTO;
import com.dianzi.certification.service.UserService;
import com.dianzi.certification.vo.R;
import com.dianzi.certification.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author copa
 * @createDate 2022-03-07 22:38
 * @function
 */
@RestController
@Api(tags = {"用户登录验证与注册"})
@RequestMapping("auth")
public class AuthController {

    @Resource
    private UserService userService;

    @PostMapping("login")
    @ApiOperation(value = "登录")
    public R<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        return userService.login(userLoginDTO);
    }

    @PreAuthorize("ROLE_ADMIN")
    @PostMapping("register")
    @ApiOperation(value = "管理员新增账号")
    public R<String> register(@RequestBody UserRegisterDTO userRegisterDTO) {
        return userService.register(userRegisterDTO);
    }
}
